package 文件IO.Scanner调用流;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(InputStream inputStream = new FileInputStream("E:/test.txt")){
            Scanner sc = new Scanner(inputStream);

            // 使用 StringBuilder 来构建整个文件内容
            StringBuilder content = new StringBuilder();

            // 读取文件中的每一行并将其添加到 StringBuilder 中
            while (sc.hasNextLine()) {
                content.append(sc.nextLine()).append(System.lineSeparator());
            }

            // 显示文件内容
            System.out.println(content.toString());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
